﻿using System;
using System.Collections.Generic;

namespace WinRTFramework.FrameworkConfiguration
{
    public interface IIoCAdapter
    {
        IEnumerable<Type> GetAllRegisteredTypes();
        
        object GetInstanceOfType(Type t);
    }

    public static class IIoCAdapterExtensions
    {
        public static IEnumerable<Type> GetAllRegisteredTypesThatImplement<T>(this IIoCAdapter adapter)
        {
            foreach(var registeredType in adapter.GetAllRegisteredTypes())
            {
                var instance = adapter.GetInstanceOfType(registeredType);
                if (instance is T)
                {
                    yield return registeredType;
                }
            }
        }
    }
}
